package com.zefor.plugin;

import com.zefor.pojo.*;
import com.zefor.utils.AdmqUtil;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;


import java.io.IOException;
import java.io.InputStream;
import java.util.*;

/**
 * @version V1.0
 * @作者: 16847
 * @创建时间: 2023/5/16 11:00
 * @描述:
 * @包位置: com.zefor.plugin
 */

public class Plugin2 extends AbstractListPlugin {


    // 厂房信息
    private String factoryName;
    private String factoryStatus;



    @Override
    public void afterCreateNewData(EventObject e) {
        super.afterCreateNewData(e);

        // 读取当前厂房信息
        try (InputStream in = this.getClass().getResourceAsStream("/FactoryDetail.properties");){
            Properties properties = new Properties();
            properties.load(in);
            factoryName = (String) properties.get("name");
            factoryStatus = (String) properties.get("status");
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }

        // 获取表单对象
        DynamicObject monitoring = BusinessDataServiceHelper.newDynamicObject("n716_plant_monitoring");
        //设置基础信息
        monitoring.set("fbillno", factoryName);
        monitoring.set("billstatus", factoryStatus);
        long id = UserServiceHelper.getCurrentUserId();


        // 实体对象


        // 基础表单对象
        DynamicObjectCollection envEntity = monitoring.getDynamicObjectCollection("n716_enventity");

        // 获取集合类型
        DynamicObjectType type = envEntity.getDynamicObjectType();
        // 创建单据实体
        DynamicObject entity = new DynamicObject(type);

        // 环控
        // 添加到集合中
        envEntity.add(entity);

        //用水量



        //电量



        //保存数据
        SaveServiceHelper.saveOperate("n716_plant_monitoring", new DynamicObject[]{monitoring});
    }



}
